package com.travel.util;

import java.util.*;

public class SignUtil {
    //id=xxx&name=xxx
    public static String getSign(Map<String, String[]> params) {
        List<String> keys = new ArrayList<>();
        for (String s : params.keySet()) {
            if ("sign".equals(s)) {
                continue;
            }
            keys.add(s);
        }
        Collections.sort(keys);
        StringBuilder sb = new StringBuilder();
        for (String key : keys) {
            sb.append(key).append("=").append(params.get(key)[0]).append("&");
        }
        if (sb.length() > 0) {
            return sb.substring(0, sb.length() - 1);
        }
        return sb.toString();
    }

    public static void main(String[] args) {
        Map<String, String[]> params = new HashMap<>();
        params.put("congtent", new String[]{"123"});
        params.put("absd", new String[]{"xxx"});
        params.put("title", new String[]{"aaa"});
        params.put("ssss", new String[]{"qqq"});
        params.put("sign", new String[]{"asfafasfqqq"});
        System.out.println(getSign(params));
    }
}
